package d20chat;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.WindowConstants;
import javax.swing.filechooser.FileFilter;

public class MapViewer extends JFrame {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		
		
		ArrayList<Terrain> a = new ArrayList<Terrain>();
		a.add(new Terrain("grass", new Color(150, 255, 150)));
		a.add(new Terrain("water", new Color(150, 150, 255)));
		a.add(new Terrain("rock", new Color(150, 150, 150)));
		a.add(new Terrain("<blank>", new Color(255, 255, 255)));
		a.add(new Terrain("<void>", new Color(0, 0, 0)));
		a.add(new Terrain("<void>", new Color(0, 0, 0)));
		a.add(new Terrain("<void>", new Color(0, 0, 0)));
		a.add(new Terrain("<void>", new Color(0, 0, 0)));
		a.add(new Terrain("<void>", new Color(0, 0, 0)));
		a.add(new Terrain("<void>", new Color(0, 0, 0)));
		a.add(new Terrain("<void>", new Color(0, 0, 0)));
		a.add(new Terrain("<void>", new Color(0, 0, 0)));
		a.add(new Terrain("<void>", new Color(0, 0, 0)));
		a.add(new Terrain("<bgv>", new Color(238, 238, 238)));
		
		String ttt = "";
		for (int x=0; x<a.size(); x++)
		{
			ttt += a.get(x) + "\n";
		}
		
		
		File f = new File("maps");
		
		try {
			if (!f.exists()) f.mkdir();
			f = new File ("maps\\terrains.tr");
			if (!f.exists())f.createNewFile();
			FileWriter fw = new FileWriter(f);
			fw.write(ttt);
			fw.close();
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		MapViewer t = new MapViewer(new D20Chat());
		
		MapSquare g = new MapSquare(new Terrain("grass", new Color(0, 255, 0)), 0, "");
		System.out.println(g.getTerrain());
		System.out.println(t);
		
		
		
		
		MapSquare[][] gs = new MapSquare[10][15];
		for (int x=0; x<gs.length; x++)
			for (int y=0; y<gs[x].length; y++)
			{
				gs[x][y] = new MapSquare(new Terrain("water", new Color(150, 150, 255)), 0, "YP", 0);
			}
		
//		try {
//			Thread.sleep(5000);
//		} catch (InterruptedException e) {
//			e.printStackTrace();
//		}
//		t.setMap(gs);
		
	}
	
	MapViewer thisthing;
	MapSquare[][] gs;
	MapPanel mp;
	JTextArea displayt;
	JScrollPane jsp;
	JMenuBar mb;
	JMenu mfile, moptions, mGM;
	JMenuItem minew, miopen, misave, miclose, miShowEditor, mioptions, miSendMap, mitsave;
	MapEditPanel mep;
	D20Chat main;
	
	static final String terrain_path = "maps\\terrains.tr";
	
	boolean isGM = true;
	boolean showEditor = true;
	
	boolean display_highlight = true;
	boolean fixed_square = false;
	int fixed_square_x = 0;
	int fixed_square_y = 0;


	
	int pixelSize = 20;

	public MapViewer(D20Chat m) {
		this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
		thisthing  = this;
		main = m;
		isGM = true;
		gs = new MapSquare[1][0];
//		gs = new MapSquare[30][30];
//		for (int x=0; x<gs.length; x++)
//			for (int y=0; y<gs[x].length; y++)
//				gs[x][y] = new MapSquare(new Terrain("grass", new Color(150, 255, 150)), 0, "YP", 1);
		
//		String sss = "DDMap(30x30)[[H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)][H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150),H0CYP-T1Tgrass(150,255,150)]]";
//		gs = parseMap(sss);
		
		File f = new File("mapv.prop");
		if (!f.exists())
			try {
				f.createNewFile();
			} catch (IOException e3) {
				e3.printStackTrace();
			}
		Properties p = new Properties();
		try {
			p.load(new FileReader("mapv.prop"));
		} catch (FileNotFoundException e2) {
			e2.printStackTrace();
		} catch (IOException e2) {
			e2.printStackTrace();
		}
		
		
		mp = new MapPanel(gs.length, gs[0].length);
		JPanel display = new JPanel();
		JLabel displayl = new JLabel("Square: -\nHeight: -\nContains: -\nTerrain: -");
		displayl.setVerticalAlignment(JLabel.TOP);
		
		displayt = new JTextArea("Square: -\nHeight: -\nContains: -\nTerrain: -");
		displayt.setEditable(false);

		mp.addMouseMotionListener(new MouseMotionListener() {
		
			@Override
			public void mouseMoved(MouseEvent e) {
				if (fixed_square) return;
				int x = e.getX()/pixelSize;
				int y = e.getY()/pixelSize;
				fixed_square_x = x;
				fixed_square_y = y;
				
				if (x>=gs.length || y>= gs[0].length)
				{
					display_highlight = false;
					displayt.setText("Square: -\nHeight: -\nContains: -\nTerrain: -");
					mp.repaint();
					return;
				}
				
				display_highlight = true;
				
				String text = "Square: ("+x+","+y+")\n";
				text += "Height: "+gs[x][y].getHeight()+"\n";
				text += "Contains: "+gs[x][y].getContent()+"\n";
				text += "Terrain: "+gs[x][y].getTerrain().getName();
				displayt.setText(text);
				mp.repaint();
			}
		
			@Override
			public void mouseDragged(MouseEvent e) {
				
				if (e.getModifiers()== MouseEvent.BUTTON3_MASK)
				{
					int x = e.getX()/pixelSize;
					int y = e.getY()/pixelSize;
					
					
					if (x>=gs.length || y>= gs[0].length)
					{
						display_highlight = false;
						fixed_square = false;
						displayt.setText("Square: -\nHeight: -\nContains: -\nTerrain: -");
						mp.repaint();
						return;
					}
					
					mep.setData(gs[x][y]);
					
					display_highlight = false;
					fixed_square = false;
					
					String text = "Square: ("+x+","+y+")\n";
					text += "Height: "+gs[x][y].getHeight()+"\n";
					text += "Contains: "+gs[x][y].getContent()+"\n";
					text += "Terrain: "+gs[x][y].getTerrain().getName();
					displayt.setText(text);
				} else if (mep.mode == 2)
				{
					if (e.getModifiers()== MouseEvent.BUTTON1_MASK)
					{
						int x = e.getX()/pixelSize;
						int y = e.getY()/pixelSize;

						
						if (x>=gs.length || y>=gs[0].length)
						{
							display_highlight = false;
							fixed_square = false;
							displayt.setText("Square: -\nHeight: -\nContains: -\nTerrain: -");
							mp.repaint();
							return;
						}
						
						gs[x][y] = mep.getData();
						
						display_highlight = false;
						fixed_square = false;
						
						String text = "Square: ("+x+","+y+")\n";
						text += "Height: "+gs[x][y].getHeight()+"\n";
						text += "Contains: "+gs[x][y].getContent()+"\n";
						text += "Terrain: "+gs[x][y].getTerrain().getName();
						displayt.setText(text);
					}
				}
				
				
				mp.repaint();
			}
		});
		mp.addMouseListener(new MouseListener() {
		
			@Override
			public void mouseReleased(MouseEvent e) {
			}
		
			@Override
			public void mousePressed(MouseEvent e) {
			}
		
			@Override
			public void mouseExited(MouseEvent e) {
				display_highlight = false;
				if (!fixed_square) displayt.setText("Square: -\nHeight: -\nContains: -\nTerrain: -");
				mp.repaint();
			}
		
			@Override
			public void mouseEntered(MouseEvent e) {
//				int x = e.getX()/pixelSize;
//				int y = e.getY()/pixelSize;
//				
//				if (x>=gs.length || y>= gs[0].length)
//				{
//					display_highlight = false;
//					displayt.setText("Square: -\nHeight: -\nContains: -\nTerrain: -");
//				} else display_highlight = true;
				display_highlight = true;
				
//				mp.repaint();
			}
		
			@Override
			public void mouseClicked(MouseEvent e) {
				if (mep.mode == 1)
				{
					if (e.getButton()==MouseEvent.BUTTON3)
					{
						fixed_square = false;
						display_highlight = false;
						mp.repaint();
						return;
					} else if (e.getButton() == MouseEvent.BUTTON1)
					{
						int x = e.getX()/pixelSize;
						int y = e.getY()/pixelSize;
						fixed_square_x = x;
						fixed_square_y = y;
						
						
						if (x>=gs.length || y>= gs[0].length)
						{
							display_highlight = false;
							fixed_square = false;
							displayt.setText("Square: -\nHeight: -\nContains: -\nTerrain: -");
							mp.repaint();
							return;
						}
						
						display_highlight = true;
						
						
						String text = "Square: ("+x+","+y+")\n";
						text += "Height: "+gs[x][y].getHeight()+"\n";
						text += "Contains: "+gs[x][y].getContent()+"\n";
						text += "Terrain: "+gs[x][y].getTerrain().getName();
						displayt.setText(text);
						fixed_square = true;
					}
				} else if (mep.mode == 2)
				{
					if (e.getButton()==MouseEvent.BUTTON3)
					{
						int x = e.getX()/pixelSize;
						int y = e.getY()/pixelSize;
						
						
						if (x>=gs.length || y>= gs[0].length)
						{
							display_highlight = false;
							fixed_square = false;
							displayt.setText("Square: -\nHeight: -\nContains: -\nTerrain: -");
							mp.repaint();
							return;
						}
						
						mep.setData(gs[x][y]);
						
						display_highlight = false;
						fixed_square = false;
						
						String text = "Square: ("+x+","+y+")\n";
						text += "Height: "+gs[x][y].getHeight()+"\n";
						text += "Contains: "+gs[x][y].getContent()+"\n";
						text += "Terrain: "+gs[x][y].getTerrain().getName();
						displayt.setText(text);
					} else if (e.getButton() == MouseEvent.BUTTON1)
					{
						int x = e.getX()/pixelSize;
						int y = e.getY()/pixelSize;
						
						
						if (x>=gs.length || y>= gs[0].length)
						{
							display_highlight = false;
							fixed_square = false;
							displayt.setText("Square: -\nHeight: -\nContains: -\nTerrain: -");
							mp.repaint();
							return;
						}
						
						gs[x][y] = mep.getData();
						
						display_highlight = false;
						fixed_square = false;
						
						String text = "Square: ("+x+","+y+")\n";
						text += "Height: "+gs[x][y].getHeight()+"\n";
						text += "Contains: "+gs[x][y].getContent()+"\n";
						text += "Terrain: "+gs[x][y].getTerrain().getName();
						displayt.setText(text);
					}
				}
				
				
				mp.repaint();
			}
		});
		
		

		this.setSize(450, 600);
		this.setResizable(true);
		this.setLocation(900, 50);
		this.setTitle("Map Test");
		
		jsp = new JScrollPane(mp);
		jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		// jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		// jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		
		mep = new MapEditPanel();
		mep.setPreferredSize(mep.getSize());
		mep.setVisible(showEditor && isGM);
		
		BorderLayout bl = new BorderLayout();
		//TODO
		this.add(mep, BorderLayout.WEST);
		this.add(jsp,BorderLayout.CENTER);
		this.add(displayt, BorderLayout.SOUTH);
		
		
		
		
		
		
		mb = new JMenuBar();
		mfile = new JMenu("File");
		moptions = new JMenu("Options");
		mGM = new JMenu("GM");
		miSendMap = new JMenuItem("Send Map");
		
		miSendMap.addActionListener(new ActionListener() {
		
			@Override
			public void actionPerformed(ActionEvent e) {
				main.clientthread.updateMapOnServer(thisthing.toString());
			}
		});
		
		minew = new JMenuItem("New");
		miopen = new JMenuItem("Open");
		misave = new JMenuItem("Save");
		miclose = new JMenuItem("Quit");
		mioptions = new JMenuItem("Options");
		mitsave = new JMenuItem("Save Terrain");
		miShowEditor = new JMenuItem("Toggle editor");
		
		minew.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				if (!isGM) 
				{
					JOptionPane.showMessageDialog(thisthing, "only GM's can make new maps");
					return;
				}
				int xx = Integer.parseInt(JOptionPane.showInputDialog("x"));
				int yy = Integer.parseInt(JOptionPane.showInputDialog("y"));
				MapSquare[][] ms = new MapSquare[xx][yy];
				for (int x=0; x<xx; x++)
					for (int y=0; y<yy; y++)
						ms[x][y] = new MapSquare();
				setMap(ms);
			}
		});
		
		miopen.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				if (!isGM) 
				{
					JOptionPane.showMessageDialog(thisthing, "only GM's can make new maps");
					return;
				}
				JFileChooser fc = new JFileChooser(System.getProperty("lastaccesseddir"));
				fc.setFileFilter(new FileFilter() {
				
					@Override
					public String getDescription() {
						return null;
					}
				
					@Override
					public boolean accept(File f) {
						if (f.getPath().substring(f.getPath().lastIndexOf('.')+1).equalsIgnoreCase("map"))
							return true;
						else if (f.isDirectory()) return true;
						return false;
					}
				});
				fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
				fc.showOpenDialog(thisthing);
				File f = fc.getSelectedFile();
				try {
					setMap(getMap(f));
				} catch (IOException e1) {
					e1.printStackTrace();
				}
				System.setProperty("lastaccesseddir", f.getAbsolutePath().substring(0,f.getAbsolutePath().lastIndexOf('\\')+1));
			}
		});
		
		misave.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				JFileChooser fc = new JFileChooser(System.getProperty("lastaccesseddir"));
				fc.setFileFilter(new FileFilter() {
				
					@Override
					public String getDescription() {
						return null;
					}
				
					@Override
					public boolean accept(File f) {
						if (f.getPath().substring(f.getPath().lastIndexOf('.')+1).equalsIgnoreCase("map"))
							return true;
						else if (f.isDirectory()) return true;
						return false;
					}
				});
				fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
				fc.showSaveDialog(thisthing);
				File f = fc.getSelectedFile();
				if (!f.getName().substring(f.getName().length()-4).equalsIgnoreCase(".map"))
					f = new File(f.getAbsolutePath()+".map");
				try {
					saveMap(f, thisthing.toString());
					saveTerrain(MapViewer.terrain_path, mep.savedterrain);
				} catch (IOException e1) {
					e1.printStackTrace();
				}
				System.setProperty("lastaccesseddir", f.getAbsolutePath().substring(0,f.getAbsolutePath().lastIndexOf('\\')+1));
			}
		});

		miclose.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				thisthing.dispose();
			}
		});
		
		miShowEditor.addActionListener(new ActionListener() {
		
			@Override
			public void actionPerformed(ActionEvent e) {
				showEditor = !showEditor;
				mep.setVisible(showEditor && isGM);
		
			}
		});
		
		mitsave.addActionListener(new ActionListener() {
		
			@Override
			public void actionPerformed(ActionEvent e) {
				try {
					saveTerrain("maps\\terrains.tr", mep.savedterrain);
				} catch (IOException e1) {

					e1.printStackTrace();
				}
		
			}
		});
		
		mioptions.addActionListener(new ActionListener() {
		
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
		
			}
		});
		
		mfile.add(minew);
		mfile.add(miopen);
		mfile.add(misave);
		mfile.add(miclose);
		moptions.add(mioptions);
		if (isGM)
		{
			moptions.add(miShowEditor);
			moptions.add(mitsave);
		}
			
		mGM.add(miSendMap);
		
		mb.add(mfile);
		mb.add(moptions);
		if (isGM)
			mb.add(mGM);
		
		this.setJMenuBar(mb);
		
		
		
//		this.setVisible(true);

	}
	
	public void setMap(MapSquare[][] a)
	{
		gs = a;
		mp.repaint();
	}
	
	public String toString()
	{
		String s = "DDMap("+gs.length+"x"+gs[0].length+")";
		s += "[";
		for (int x=0; x<gs.length; x++)
		{
			s += "[";
			for (int y=0; y<gs[x].length; y++)
			{
				s += gs[x][y];
				if (y<gs[x].length-1) s += ",";
			}
			s += "]";
		}
		s += "]";
		
		return s;
	}
	
	public void updateMapFromServer()
	{
		
	}
	
	class MapPanel extends JPanel {

		int gridx = 30;
		int gridy = 30;
		double font_spacing_x = 0.07;
		double font_spacing_y = 0.24;
		Color highlight = new Color(255,0,0);
		
		public MapPanel() {

		}
		
		public MapPanel(int x, int y) {
			gridx = x;
			gridy = y;
		}

		@Override
		public void paint(Graphics g) {
			super.paint(g);
			
			gridx = gs.length;
			gridy = gs[0].length;
			
			
			Graphics2D g2 = (Graphics2D) g;
			
			
			
			g2.setColor(Color.DARK_GRAY);
			g2.fillRect(0, 0, gridx * pixelSize, gridy * pixelSize);
			g2.setColor(Color.WHITE);
			g2.fillRect(0, 0, gridx * pixelSize, gridy * pixelSize);
			
			for (int x=0; x<gs.length; x++)
				for (int y=0; y<gs[x].length; y++)
				{
					g2.setColor(gs[x][y].getTerrain().getColor());
					g2.fillRect(x*pixelSize, y*pixelSize, pixelSize, pixelSize);
				}
			
			g2.setColor(Color.BLACK);
			g2.drawLine(0, 0, gridx * pixelSize, 0);
			g2.drawLine(0, 0, 0, gridy * pixelSize);
			g2.drawLine(gridx * pixelSize, gridy * pixelSize, 0, gridy * pixelSize);
			g2.drawLine(gridx * pixelSize, gridy * pixelSize, gridx * pixelSize, 0);
			g2.setColor(Color.BLACK);
			for (int i = 1; i < gridx; i++) {
				g2.drawLine(pixelSize * i, 0, pixelSize * i, pixelSize * gridy);
			}
			for (int i = 1; i < gridy; i++) {
				g2.drawLine(0, pixelSize * i, pixelSize * gridx, pixelSize * i);
			}
			// for(int k = 0; k < 32; k++){
			// for(int j = 0; j < 32; j++){
			// g2.setColor(picture[k][j]);
			// g2.fillRect(k * pixelSize + 1, j * pixelSize + 1, pixelSize - 2,
			// pixelSize - 2);
			// }
			// }
			g2.setFont(new Font("Times New Roman", Font.PLAIN, (int)(pixelSize*0.7)));
			for (int x=0; x<gs.length; x++)
				for (int y=0; y<gs[x].length; y++)
				{
					switch(gs[x][y].getType())
					{
					case 1: g2.setColor(new Color(0,0,150)); break;
					case 2: g2.setColor(new Color(150,0,0)); break;
					case 0:
					default: g2.setColor(Color.black); break;
					}
					
					g2.drawString(gs[x][y].getContent(), x*pixelSize+(int)(pixelSize*font_spacing_x), y*pixelSize+pixelSize/2+(int)(pixelSize*font_spacing_y));
//					g2.drawString(gs[x][y].getContent(), x*pixelSize+(int)(pixelSize*0.1), y*pixelSize+pixelSize/2+(int)(pixelSize*0.3));
				}

			if (display_highlight || fixed_square && fixed_square_x < gs.length && fixed_square_y < gs[0].length)
			{
				g2.setColor(highlight);
				g2.drawLine((fixed_square_x)*pixelSize, (fixed_square_y)*pixelSize, (fixed_square_x)*pixelSize, (fixed_square_y+1)*pixelSize);
				g2.drawLine((fixed_square_x+1)*pixelSize, (fixed_square_y)*pixelSize, (fixed_square_x+1)*pixelSize, (fixed_square_y+1)*pixelSize);
				g2.drawLine((fixed_square_x)*pixelSize, (fixed_square_y)*pixelSize, (fixed_square_x+1)*pixelSize, (fixed_square_y)*pixelSize);
				g2.drawLine((fixed_square_x)*pixelSize, (fixed_square_y+1)*pixelSize, (fixed_square_x+1)*pixelSize, (fixed_square_y+1)*pixelSize);
			}
			
			this.setPreferredSize(new Dimension(gridx * pixelSize, gridy * pixelSize));

		}
	}
	
	class MapInfoPanel extends JPanel{
		private String text;
		public MapInfoPanel() {

		}
	}
	
	class MapEditPanel extends JPanel{
		private String text;
		JTextField cellcontents;
		JTextField cellheight;
		JTextField terrainname;
		JComboBox celltype;
		JLabel lcontents, lheight, ltname, ltcolor, ltsaved;
		Color tcolor;
		JPanel tcolord;
		JList tsaved;
		JScrollPane tsavedp;
		ArrayList<Terrain> savedterrain;
		JButton tsave, tload, tdelete, toverwrite, tnew, cellclear;
		JRadioButton normalmode, editmode;
		ButtonGroup modes;
		

		
//		1 = normal
//		2 = paint
		int mode = 1;
		
		int width = 150;
		int height = 200;
		SpringLayout sl;
		
		public MapEditPanel() {
			this.setSize(width, height);
			cellcontents = new JTextField(5);
			cellheight = new JTextField(5);
			terrainname = new JTextField(5);
			sl = new SpringLayout();
			lcontents = new JLabel("Contents");
			lheight = new JLabel("Height");
			ltname = new JLabel("Terrain");
			ltcolor = new JLabel("Color");
			ltsaved = new JLabel("Saved Terrains");
			tcolor = new Color(255,255,255);
			String[] celltype_choices = {"Common","PC","Enemies"};
			celltype = new JComboBox(celltype_choices);
			

			
			normalmode = new JRadioButton("Normal");
			editmode = new JRadioButton("Edit");
			modes = new ButtonGroup();
			modes.add(normalmode);
			modes.add(editmode);
			normalmode.setSelected(true);
//			normalmode.setActionCommand("1");
//			editmode.setActionCommand("2");
			normalmode.addActionListener(new ActionListener() {
			
				@Override
				public void actionPerformed(ActionEvent e) {
					mode = 1;
				}
			});
			editmode.addActionListener(new ActionListener() {
			
				@Override
				public void actionPerformed(ActionEvent e) {
					mode = 2;
				}
			});

			tcolord = new JPanel();
			tcolord.setSize(75,18);
			tcolord.setPreferredSize(tcolord.getSize());
			tcolord.setBackground(tcolor);
			tcolord.addMouseListener(new MouseListener() {
			
				@Override
				public void mouseReleased(MouseEvent e) {
			
				}
			
				@Override
				public void mousePressed(MouseEvent e) {
			
				}
			
				@Override
				public void mouseExited(MouseEvent e) {
			
				}
			
				@Override
				public void mouseEntered(MouseEvent e) {
			
				}
			
				@Override
				public void mouseClicked(MouseEvent e) {
					tcolor = JColorChooser.showDialog(null, "Terrain color", tcolor);
					tcolord.setBackground(tcolor);
				}
			});
			
			
			savedterrain = new ArrayList<Terrain>();
			savedterrain.add(new Terrain("grass", new Color(150, 255, 150)));
			savedterrain.add(new Terrain("water", new Color(150, 150, 255)));
			savedterrain.add(new Terrain("rock", new Color(150, 150, 150)));
			savedterrain.add(new Terrain("<blank>", new Color(255, 255, 255)));
			savedterrain.add(new Terrain("<void>", new Color(0, 0, 0)));
			savedterrain.add(new Terrain("<bgv>", new Color(238, 238, 238)));
			
			
			
			
			File f = new File("maps");
			
			try {
				if (!f.exists()) f.mkdir();
				f = new File ("maps\\terrains.tr");
				if (!f.exists())
				{
					f.createNewFile();
					savedterrain.add(new Terrain("grass", new Color(150, 255, 150)));
					savedterrain.add(new Terrain("water", new Color(150, 150, 255)));
					savedterrain.add(new Terrain("rock", new Color(150, 150, 150)));
					savedterrain.add(new Terrain("<blank>", new Color(255, 255, 255)));
					savedterrain.add(new Terrain("<void>", new Color(0, 0, 0)));
					savedterrain.add(new Terrain("<bgv>", new Color(238, 238, 238)));
					saveTerrain(terrain_path, savedterrain);
				} else
				{
					savedterrain = loadTerrain(MapViewer.terrain_path);
				}
				
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			savedterrain = pruneDoublesFromList(savedterrain);
			
			tsaved = new JList(savedterrain.toArray(new Terrain[0]));
			tsaved.setBackground(Color.white);
			
			tsavedp = new JScrollPane(tsaved, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
			
			cellclear = new JButton("Clear");
			cellclear.addActionListener(new ActionListener() {
			
				@Override
				public void actionPerformed(ActionEvent e) {
					cellcontents.setText("");
					cellheight.setText("0");
					celltype.setSelectedIndex(0);
					terrainname.setText("");
					tcolor = Color.white;
					tcolord.setBackground(tcolor);
				}
			});
			
			tload = new JButton("load");
			tload.addActionListener(new ActionListener() {
			
				@Override
				public void actionPerformed(ActionEvent e) {
					Terrain i = (Terrain)tsaved.getSelectedValue();
					if (i != null)
					{
						terrainname.setText(i.getName());
						tcolor = i.getColor();
						tcolord.setBackground(tcolor);
					}
				}
			});
			
			tdelete = new JButton("delete");
			tdelete.addActionListener(new ActionListener() {
			
				@Override
				public void actionPerformed(ActionEvent e) {
					int i = tsaved.getSelectedIndex();
					if (i>-1)
					{
						savedterrain.remove(i);
						tsaved.setListData(savedterrain.toArray(new Terrain[0]));
						try {
							saveTerrain(MapViewer.terrain_path, mep.savedterrain);
						} catch (IOException e1) {
							e1.printStackTrace();
						}
					}
				}
			});
			
			tsave = new JButton("save");
			tsave.addActionListener(new ActionListener() {
			
				@Override
				public void actionPerformed(ActionEvent e) {
					Terrain t = new Terrain(terrainname.getText(), tcolor);
					savedterrain.add(t);
					tsaved.setListData(savedterrain.toArray(new Terrain[0]));
					try {
						saveTerrain(terrain_path, savedterrain);
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
			});
			
			toverwrite = new JButton("overwrite");
			toverwrite.addActionListener(new ActionListener() {
			
				@Override
				public void actionPerformed(ActionEvent e) {
					int i = tsaved.getSelectedIndex();
					if (i>-1)
					{
						savedterrain.remove(i);
						Terrain t = new Terrain(terrainname.getText(), tcolor);
						savedterrain.add(i, t);
						tsaved.setListData(savedterrain.toArray(new Terrain[0]));
					} else
					{
						Terrain t = new Terrain(terrainname.getText(), tcolor);
						savedterrain.add(t);
						tsaved.setListData(savedterrain.toArray(new Terrain[0]));
					}
					try {
						saveTerrain(terrain_path, savedterrain);
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
			});
			
			tnew = new JButton("new");
			tnew.addActionListener(new ActionListener() {
			
				@Override
				public void actionPerformed(ActionEvent e) {
					terrainname.setText("");
					tcolor = Color.white;
					tcolord.setBackground(tcolor);
				}
			});
			
			
			this.setLayout(sl);
			this.add(lcontents);
			this.add(cellcontents);
			this.add(lheight);
			this.add(cellheight);
			this.add(celltype);
			this.add(ltname);
			this.add(terrainname);
			this.add(ltcolor);
			this.add(tcolord);
			this.add(ltsaved);
			this.add(tsavedp);
			this.add(tload);
			this.add(tdelete);
			this.add(tsave);
			this.add(toverwrite);
			this.add(tnew);
			this.add(normalmode);
			this.add(editmode);
			this.add(cellclear);
			
			
			sl.putConstraint(SpringLayout.WEST, lcontents, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, lcontents, 5, SpringLayout.NORTH, this);
			
			sl.putConstraint(SpringLayout.WEST, cellcontents, 5, SpringLayout.EAST, lcontents);
			sl.putConstraint(SpringLayout.NORTH, cellcontents, 0, SpringLayout.NORTH, lcontents);
			
			sl.putConstraint(SpringLayout.WEST, lheight, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, lheight, 5, SpringLayout.SOUTH, cellcontents);
			
			sl.putConstraint(SpringLayout.WEST, cellheight, 5, SpringLayout.EAST, lheight);
			sl.putConstraint(SpringLayout.NORTH, cellheight, 0, SpringLayout.NORTH, lheight);
			
			sl.putConstraint(SpringLayout.WEST, celltype, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, celltype, 5, SpringLayout.SOUTH, cellheight);
			
			sl.putConstraint(SpringLayout.WEST, ltname, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, ltname, 5, SpringLayout.SOUTH, celltype);
			
			sl.putConstraint(SpringLayout.WEST, terrainname, 5, SpringLayout.EAST, ltname);
			sl.putConstraint(SpringLayout.NORTH, terrainname, 0, SpringLayout.NORTH, ltname);
			
			sl.putConstraint(SpringLayout.WEST, ltcolor, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, ltcolor, 5, SpringLayout.SOUTH, terrainname);
			
			sl.putConstraint(SpringLayout.WEST, tcolord, 5, SpringLayout.EAST, ltcolor);
			sl.putConstraint(SpringLayout.NORTH, tcolord, 0, SpringLayout.NORTH, ltcolor);
			
			sl.putConstraint(SpringLayout.WEST, cellclear, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, cellclear, 5, SpringLayout.SOUTH, tcolord);
			
			
			
			
			sl.putConstraint(SpringLayout.WEST, ltsaved, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, ltsaved, 5, SpringLayout.SOUTH, cellclear);
			
			sl.putConstraint(SpringLayout.WEST, tsavedp, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, tsavedp, 5, SpringLayout.SOUTH, ltsaved);
			
			sl.putConstraint(SpringLayout.WEST, tload, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, tload, 5, SpringLayout.SOUTH, tsavedp);
			
			sl.putConstraint(SpringLayout.WEST, tdelete, 0, SpringLayout.EAST, tload);
			sl.putConstraint(SpringLayout.NORTH, tdelete, 0, SpringLayout.NORTH, tload);
			
			sl.putConstraint(SpringLayout.WEST, tsave, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, tsave, 0, SpringLayout.SOUTH, tload);
			
			sl.putConstraint(SpringLayout.WEST, toverwrite, 0, SpringLayout.EAST, tsave);
			sl.putConstraint(SpringLayout.NORTH, toverwrite, 0, SpringLayout.NORTH, tsave);
			
			sl.putConstraint(SpringLayout.WEST, tnew, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, tnew, 0, SpringLayout.SOUTH, tsave);
			
			sl.putConstraint(SpringLayout.WEST, normalmode, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, normalmode, 10, SpringLayout.SOUTH, tnew);
			
			sl.putConstraint(SpringLayout.WEST, editmode, 5, SpringLayout.WEST, this);
			sl.putConstraint(SpringLayout.NORTH, editmode, 0, SpringLayout.SOUTH, normalmode);
			
			
		}
		
		public void setData(MapSquare m)
		{
			cellcontents.setText(m.getContent());
			cellheight.setText(m.getHeight()+"");
			terrainname.setText(m.getTerrain().getName());
			tcolor = m.getTerrain().getColor();
			tcolord.setBackground(tcolor);
			celltype.setSelectedIndex(m.getType());
		}
		
		public MapSquare getData()
		{
			try{
				Integer.parseInt(cellheight.getText());
			} catch (Exception er){
				cellheight.setText("0");
			}
			return new MapSquare(new Terrain(terrainname.getText(), tcolor), Integer.parseInt(cellheight.getText()), cellcontents.getText(), celltype.getSelectedIndex());
		}
	}
	
	public static ArrayList<Terrain> loadTerrain(String filename) throws IOException
	{
		ArrayList<Terrain> t = new ArrayList<Terrain>();
		
		File f = new File(filename);
//		if (!f.exists())
//		{
//			return null;
//		}
		
		BufferedReader fr = new BufferedReader(new FileReader(f));
		String temp = fr.readLine();
		while (temp != null)
		{
			t.add(Terrain.parse(temp));
			temp = fr.readLine();
		}
		
		return t;
	}
	
	public static void saveTerrain(String filename, ArrayList<Terrain> t) throws IOException
	{
		
		
		File f = new File(filename);
//		if (!f.exists())
//		{
//			return null;
//		}
		if (f.exists()) f.delete();
		
		FileWriter fw = new FileWriter(f);
		for (int x=0; x<t.size(); x++)
		{
			fw.write(t.get(x).toString()+"\n");
		}
		fw.close();
		
	}
	
	public static ArrayList<Terrain> pruneDoublesFromList(ArrayList<Terrain> t)
	{
		Iterator<Terrain> i = t.iterator();
		while (i.hasNext())
		{
			Object temp = i.next();
			System.out.println(temp);
			if (t.indexOf(temp) != t.lastIndexOf(temp))
			{
				i.remove();
			}
		}
		return t;
	}
	
	public static void saveMap(File f, String data) throws IOException
	{
		FileWriter fw = new FileWriter(f);
		fw.write(data);
		fw.close();
	}
	
	public static MapSquare[][] getMap(File f) throws IOException
	{
		BufferedReader br = new BufferedReader(new FileReader(f));
		
		String d = br.readLine();
		br.close();
		
		return parseMap(d);
	}
	
	public static MapSquare[][] parseMap(String s)
	{
		
		int x = Integer.parseInt(s.substring(6, s.indexOf('x')));
		int y = Integer.parseInt(s.substring(s.indexOf('x')+1, s.indexOf(')')));
		System.out.println(x+" "+y);
		MapSquare[][] ms = new MapSquare[x][y];
		s = s.substring(s.indexOf('[')+1);
		for (int xx=0; xx<x; xx++)
		{
			s = s.substring(s.indexOf('[')+1);
			for (int yy=0; yy<y; yy++)
			{
				System.out.println(xx+" "+yy);
				if (s.charAt(0)==',')
					s = s.substring(1);
				ms[xx][yy] = MapSquare.parse(s.substring(0, s.indexOf(')')+1));
				s = s.substring(s.indexOf(')')+1);
			}
			s = s.substring(s.indexOf(']'))+1;
		}
		
		return ms;
	}
}
